Skip to content

refactor: make the fields of MaterializedCte private - #27570

Open
adriangb wants to merge 1 commit into
apache:mainfrom
adriangb:mcte-private-fields
Open

adriangb wants to merge 1 commit into
apache:mainfrom
adriangb:mcte-private-fields

Conversation

@adriangb

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Follow-up to #26274. This PR is stacked on it: only the last commit belongs to this PR. Review #26274 first.

Rationale for this change

#26274 makes the schema and projection fields of MaterializedCteScan private, so that they always match. The MaterializedCte node still has public fields. A rule that builds the node with a struct literal or a struct update skips the scan check in MaterializedCte::try_new.

What changes are included in this PR?

  • The fields of MaterializedCte are pub(crate). Downstream code reads them through id(), name(), body() and continuation().
  • New MaterializedCte::inputs_mut and MaterializedCte::into_inputs replace the direct field access in the optimizer driver, TypeCoercion, DecorrelatePredicateSubquery, PushDownFilter, OptimizeProjections and the physical planner.
  • Rules that rebuild the node from owned inputs call try_new, so the scans are checked.

Are these changes tested?

Yes, by the existing tests. The change does not change behavior.

Are there any user-facing changes?

Yes. This is a breaking API change, which the 57.0.0 upgrade guide describes.

@github-actions github-actions Bot added documentation Improvements or additions to documentation logical-expr Logical plan and expressions optimizer Optimizer rules core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) physical-plan Changes to the physical-plan crate labels Nov 18, 2026
@adriangb
adriangb force-pushed the mcte-private-fields branch from 5b625f0 to bdf3a4d Compare November 19, 2026 17:17
A rule that builds a MaterializedCte with a struct literal or struct update
skips the scan check in try_new. Private fields send every new node through
try_new, and every in-place change through inputs_mut or with_new_inputs.

The fields are pub(crate), so the tree-node and display code of
datafusion-expr is unchanged. inputs_mut and into_inputs replace the
remaining direct field access in the optimizer and the physical planner.
@adriangb
adriangb force-pushed the mcte-private-fields branch from bdf3a4d to ffb77b4 Compare November 20, 2026 06:15
@github-actions github-actions Bot removed sqllogictest SQL Logic Tests (.slt) physical-plan Changes to the physical-plan crate labels Nov 20, 2026
@adriangb
adriangb marked this pull request as ready for review November 20, 2026 06:24
@adriangb

Copy link
Copy Markdown
Contributor Author

@kosiew mind taking a look at this small followup? This is a small change to prevent us from having to make another pub -> priv change like in #26274 (in that case so we could encode the invariant of schema and projection being in sync, hard if anything can edit them in place).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate documentation Improvements or additions to documentation logical-expr Logical plan and expressions optimizer Optimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant